package com.jozen.smart_toilet_system.dialog;


import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.NonNull;

import com.jozen.modelbase.netwoek.base.BaseDialog;
import com.jozen.modelbase.netwoek.callback.CallBack;
import com.jozen.smart_toilet_system.R;
import com.ruffian.library.widget.REditText;

/**
 * 通用配置SN码dialog，管理员自行输入SN码
 */
public class CommSettingDialog extends BaseDialog {
    private CallBack callBack;
    private REditText et_sn_code;


    //1==男厕客流量探测器，2==男厕环境探测器，3==男厕积水探测器，4==女厕客流量探测器，5==女厕环境探测器，6==女厕积水探测器
    //7==第三卫生间环境探测器，8==第三卫生间积水探测器
    private int selectType;

    public CommSettingDialog(@NonNull Activity activity) {
        super(activity);
    }


    public void setSelectType(int selectType) {
        this.selectType = selectType;
    }


    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }


    public void setOldSnCode(String snCode) {
        if (!TextUtils.isEmpty(snCode)) {
            et_sn_code.setText(snCode);
        } else {
            et_sn_code.setText("");
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.setting_dialog_layout;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        super.init(savedInstanceState);
        initView();
    }

    private void initView() {
        setCancelable(true);
        setCanceledOnTouchOutside(true);
        et_sn_code = findView(R.id.et_sn_code);
        findOnClick(R.id.btn_ok);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.btn_ok:
                if (!TextUtils.isEmpty(et_sn_code.getText().toString().trim())) {
                    if (callBack != null) {
                        callBack.call(et_sn_code.getText().toString().trim());
                        et_sn_code.setText("");
                    }
                } else {
                    dismiss();
                    et_sn_code.setText("");
                }
                break;
        }
    }
}
